import pymongo
import math
myclient = pymongo.MongoClient("mongodb://localhost:27017/")
mydb = myclient["my_db_1"]
mycol = mydb["col_2"]

# mydic = [{
  # "_id":"3123",
  # "name": "la3132oweng",
  # "age": 1533
# },{
  # "_id":"665a71e4332132346d431c747b9d172",
  # "name": "lao3132weng",
  # "age": 151
# }]

# x = mycol.insert_many(mydic)
# print(x)

myquery = {"name":"lao3132weng"}

for i in mycol.find(myquery,{"_id":0,"name":1}):
    print(i)
for i in mycol.find(myquery,{"_id":0,"name":1}).limit(4):
    print(i)

print(mycol.count_documents(myquery))


allcount = mycol.count_documents(myquery)

pageSize = 2

allpages = math.ceil(allcount/pageSize)
print(allpages)


skipCount = 0

for i in range(1,allpages+1):
    print(f"$$$$$$$$$$$$$$$$$$第{i}页$$$$$$$$$$$$$$$$$$$$")
    for j in mycol.find(myquery,{"_id":0,"name":1}).skip(skipCount).limit(pageSize):
        print(j)
    skipCount+=pageSize